package hidalgo.expenses.widgets;

import hidalgo.expenses.R;
import hidalgo.expenses.entities.Note;
import hidalgo.expenses.utils.Util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class NoteItemView extends RelativeLayout {

	private TextView txtDate;
	private TextView txtText;

	private Note note;

	public NoteItemView(Context context, Note note) {
		super(context);
		inflateLayout(context);

	}

	public NoteItemView(Context context) {
		super(context);
		inflateLayout(context);

	}

	public NoteItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		inflateLayout(context);

	}

	private void inflateLayout(Context context) {
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = layoutInflater.inflate(R.layout.note_item, this);

		this.txtText = (TextView) view.findViewById(R.id.txtText);
		this.txtDate = (TextView) view.findViewById(R.id.txtDate);
	}

	public void setNote(Note note) {
		this.note = note;

		if (note != null) {
			txtText.setText(note.getText());
			txtDate.setText(Util.getStringFromDate(note.getLastModifiedDate(),
					Util.SIMPLE_DATE_FORMAT));
		}
	}

	public Note getNote() {
		return note;
	}

}
